package cn.edu.scau.sec.rw.model.disk_file.disk;

import cn.edu.scau.sec.rw.model.disk_file.file.FileCatalog;

/**
 * 利用单例模式设计磁盘，采用顺序存储
 */
public class Disk {

    private static int block;//磁盘块大小
    private static int block_num;//磁盘块数目
    private static int[] FAT;//文件分配表
    private static Disk disk;
    private static FileCatalog root;

    private Disk(){}

    private Disk(int block, int block_num, int[] FAT) {
        this.block = block;
        this.block_num = block_num;
        this.FAT = FAT;
    }

    public static Disk getDisk(){
        if (disk == null){
            FAT = new int[256];
            //文件分配表占用4块
            //根目录占用1块
            //操作系统占11块（假定）
            root = new FileCatalog("root","根目录信息");
            System.out.println("root" + root.getStart());
            for (int i = 0; i < 16; i++) {
                FAT[i] = -1;
            }
            for (int i = 16; i < FAT.length; i++) {
                FAT[i] = 0;
            }
//            for (int i = 0; i < FAT.length; i++) {
//                System.out.print(FAT[i]+" ");
//            }
//            System.out.println(FAT.length);
            block = 64;
            block_num = 256;
            disk = new Disk(block,block_num,FAT);
        }
        return disk;
    }

    public static FileCatalog getRoot() {
        return root;
    }

    public static void setRoot(FileCatalog root) {
        Disk.root = root;
    }

    public int getBlock() {
        return block;
    }

    public void setBlock(int block) {
        this.block = block;
    }

    public int getBlock_num() {
        return block_num;
    }

    public void setBlock_num(int block_num) {
        this.block_num = block_num;
    }

    public int[] getFAT() {
        return FAT;
    }

    public void setFAT(int[] FAT) {
        this.FAT = FAT;
    }
}
